package queue;

import array.CustomArray;

public class ArrayQueue<E> implements Queue<E> {
    private CustomArray<E> array;

    public ArrayQueue() {
        this.array = new CustomArray<>();
    }

    public ArrayQueue(int capacity) {
        this.array = new CustomArray<>(capacity);
    }

    @Override
    public void enqueue(E e) {
        array.addLast(e);
    }

    @Override
    public E dequeue() {
        return array.removeFirst();
    }

    @Override
    public E getFont() {
        return array.get(0);
    }

    @Override
    public int getSize() {
        return array.getSize();
    }

    @Override
    public boolean isEmpty() {
        return array.isEmpty();
    }

    @Override
    public String toString() {
        StringBuilder res = new StringBuilder();
        res.append(String.format("Queue: size = %d ,capacity= %d\n", getSize(), array.getCapacity()));
        res.append("front [");
        for (int i = 0; i < getSize(); i++) {
            res.append(array.get(i));
            if (getSize() != i + 1) {
                res.append(",");
            }
        }
        res.append("] tail");
        return res.toString();
    }
}
